window.onload=function() {
    function user_1() {
        var i = document.querySelectorAll(".user-i");
        var user_list = document.querySelectorAll(".user-news");
        for (let j = 0, y = 0; j < i.length; j++) {
            i[j].addEventListener("click", function () {
                if (y == 0) {
                    user_list[j].style.display = "block";
                    y = 1;
                } else {
                    user_list[j].style.display = "none";
                    y = 0;
                }
            });
        }
    }

    user_1();
    function nav() {
        var main = document.querySelectorAll(".main");
        var nav = document.querySelectorAll(".nav-part");
        var p = document.querySelectorAll(".nav-part p");
        var handle = document.querySelectorAll(".main-handle");
        // 导航栏
        for (var j = 0; j < main.length; j++) {
            main[j].style.display = "none";
            nav[j].style.backgroundColor = "rgb(17, 80, 75)";
        }
        nav[0].style.backgroundColor = "rgb(45, 61, 81)";
        main[0].style.display = "block";
        p[0].style.color = "rgb(0, 162, 255)";
        handle[0].style.left = 0 + 'px';
        // 主页面的动画效果
        for (let i = 0; i < nav.length; i++) {
            nav[i].addEventListener("click", function () {
                nav[i].index = i;
                for (var j = 0; j < main.length; j++) {
                    i
                    main[j].style.display = "none";
                    nav[j].style.backgroundColor = "rgb(17, 80, 75)";
                    p[j].style.color = "rgb(191, 203, 217)";
                    handle[j].style.left = -200 + 'px';
                }
                if (this.getAttribute('num')) {
                    main[i].style.display = "block";
                    nav[i].style.backgroundColor = "rgb(45, 61, 81)";
                    p[i].style.color = "rgb(0, 162, 255)";
                    handle[i].style.left = 0 + 'px';
                } else {
                    main[i].style.display = "block";
                    nav[i].style.backgroundColor = "rgb(45, 61, 81)";
                    p[i].style.color = "rgb(0, 162, 255)";
                    animate(handle[i]);
                    for (var q = 0; q < nav.length; q++) {
                        nav[q].removeAttribute('num');
                    }
                }
                this.setAttribute('num', this.index);
            });
        }
    }

    nav();

    function animate(obj) {
        var timer = setInterval(function () {
            // var step=Math.ceil((0-obj.offsetLeft)/10);

            obj.style.left = obj.offsetLeft + 2 + 'px';
            if (obj.offsetLeft == 0) {
                clearInterval(timer);
            }
        }, 10)
    }
    var search_input1=document.querySelector(".search-input-1");
    var search_input2=document.querySelector(".search-input-2");
    var search_input3=document.querySelector(".search-input-3");
    var search_input4=document.querySelector(".search-input-4");
    var search_input5=document.querySelector(".search-input-5");
    var search_input6=document.querySelector(".search-input-6");

    var nodata=document.querySelectorAll(".nodata");
    var paging=document.querySelectorAll(".paging");
    var nav = document.querySelectorAll(".nav-part");
    nav[0].addEventListener("click",function(){
        fenYe(1,12);
        nodata[0].style.display="none";
        paging[0].style.display="block";
        search_input1.value="";
    })
    nav[1].addEventListener("click",function(){
        fenYe1(1,10);
        nodata[1].style.display="none";
        paging[1].style.display="block";
        search_input2.value="";
    })
    nav[2].addEventListener("click",function(){
        fenYe2(1,10);
        nodata[2].style.display="none";
        paging[2].style.display="block";
        search_input3.value="";
    })
    nav[3].addEventListener("click",function(){
        fenYe3(1,10);
        nodata[3].style.display="none";
        paging[3].style.display="block";
        search_input4.value="";
    })
    nav[4].addEventListener("click",function(){
        fenYe4(1,10);
        nodata[4].style.display="none";
        paging[4].style.display="block";
        search_input5.value="";
    })
    nav[5].addEventListener("click",function(){
        fenYe5(1,10);
        nodata[5].style.display="none";
        paging[5].style.display="block";
        search_input6.value="";
    })
// 点击个人中心跳转个人中心
    var User=document.querySelectorAll(".User")
    for(let i=0;i<User.length;i++){
        User[i].addEventListener("click",function(){
            window.location.href="/User/userInterface";
        })
    }
// 点击退出登录退出
    var exit=document.querySelectorAll(".exit")
    for(let i=0;i<exit.length;i++){
        exit[i].addEventListener("click",function(){
            $.ajax({
                type: "post",
                url: "/User/loginOut",
                // data: {
                // },
                success: function (data) {
                    // alert("退出")
                    window.location.href="/";

                },error: function () {
                    console.log("調取接口失敗")
                }
            })
        })
    }
    var s=document.querySelectorAll(".user-i-name");
    for(let i=0;i<s.length;i++){
        if(s[i].innerHTML=="用户名"){
            s[i].addEventListener("click",function(){
                window.location.href="/User/login";
            })
        }
    }

// 一、用户管理

    var tb = document.querySelectorAll("tbody");
    var tb1 = tb[0];
    function fenYe(a, b) {
        tb1.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectUserByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    var sex=page.page.list[i].sex||"无";
                    var telephone=page.page.list[i].telephone||"无";
                    var idCard=page.page.list[i].idCard||"无";
                    var rName=page.page.list[i].rName||"无";
                    let list = `<tr>
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='delete-1'>删除</button><button class='modify-1'>修改</button></td>
                               </tr>`;
                    tb1.insertAdjacentHTML("beforeend", list);
                }
                var delete_1=document.querySelectorAll(".delete-1");
                for(let i=0;i<page.page.list.length;i++) {
                    delete_1[i].addEventListener("click", function () {
                        if (confirm("你确定删除?")) {
                            deluser(page.page.list[i].userId);
                            alert("删除成功");
                        } else {
                            alert("删除失败");
                        }
                    })
                }

                // 修改中input中显示之前的值
                var nickname=document.querySelectorAll(".nickname")[0];
                var rName=document.querySelectorAll(".rName")[0];
                var sex=document.querySelectorAll(".sex")[0];
                var telephone=document.querySelectorAll(".telephone")[0];
                // 修改
                var modify_1=document.querySelectorAll(".modify-1");
                var modify_user1=document.querySelectorAll(".modify-user")[0];
                var goback1=document.querySelectorAll(".btn-goback")[0];
                for(let i=0;i<page.page.list.length;i++) {
                    modify_1[i].addEventListener("click", function () {
                        modify_user1.style.display = "block";
                        if(page.page.list[i].nickname==null){
                            nickname.value="无";
                        }else {
                            nickname.value = page.page.list[i].nickname;
                        }
                        if(page.page.list[i].rName==null){
                            rName.value="无";
                        }else {
                            rName.value = page.page.list[i].rName;
                        }
                        if(page.page.list[i].sex==null){
                            sex.value="无"
                        }else {
                            sex.value = page.page.list[i].sex;
                        }
                        if(page.page.list[i].telephone==null){
                            telephone.value="无"
                        }else {
                            telephone.value = page.page.list[i].telephone;
                        }
                        modify1(page.page.list[i].userId);

                    })
                }
                goback1.addEventListener("click", function () {
                    modify_user1.style.display = "none";
                })
            }
        })
    }
// 搜索
    var search_input1=document.querySelector(".search-input-1");
    var search_btn1=document.querySelector(".search-btn-1");
    search_btn1.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeUserByPage",
            data: {
                nickName: search_input1.value,
                pageNow: 1,
                pageSize: 12
            },
            success: function (page) {
                if (search_input1.value == "") {
                    alert("输入的内容为空")
                    fenYe(1, 12);
                    nodata[0].style.display = "none";
                } else {
                    tb1.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        var sex=page.page.list[i].sex||"无";
                        var telephone=page.page.list[i].telephone||"无";
                        var idCard=page.page.list[i].idCard||"无";
                        var rName=page.page.list[i].rName||"无";
                        let list = `<tr>
                                   
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='delete-1'>删除</button><button class='modify-1'>修改</button></td>
                               </tr>`;
                        tb1.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb1.innerHTML==""){
                        alert("对不起,找不到搜索内容");
                        nodata[0].style.display="block";
                        paging[0].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[0].style.display = "none";
                        paging[0].style.display = "block";
                    }

                    var delete_1=document.querySelectorAll(".delete-1");
                    for(let i=0;i<page.page.list.length;i++) {
                        delete_1[i].addEventListener("click", function () {
                            if (confirm("你确定删除?")) {
                                deluser(page.page.list[i].userId);
                                alert("删除成功");
                            } else {
                                alert("删除失败");
                            }
                        })
                    }
                    // 修改中input中显示之前的值
                    var nickname=document.querySelectorAll(".nickname")[0];
                    var rName=document.querySelectorAll(".rName")[0];
                    var sex=document.querySelectorAll(".sex")[0];
                    var telephone=document.querySelectorAll(".telephone")[0];
                    // 修改
                    var modify_1=document.querySelectorAll(".modify-1");
                    var modify_user1=document.querySelectorAll(".modify-user")[0];
                    var goback1=document.querySelectorAll(".btn-goback")[0];
                    for(let i=0;i<page.page.list.length;i++) {
                        modify_1[i].addEventListener("click", function () {
                            modify_user1.style.display = "block";
                            if(page.page.list[i].nickname==null){
                                nickname.value="无";
                            }else {
                                nickname.value = page.page.list[i].nickname;
                            }
                            if(page.page.list[i].rName==null){
                                rName.value="无";
                            }else {
                                rName.value = page.page.list[i].rName;
                            }
                            if(page.page.list[i].sex==null){
                                sex.value="无"
                            }else {
                                sex.value = page.page.list[i].sex;
                            }
                            if(page.page.list[i].telephone==null){
                                telephone.value="无"
                            }else {
                                telephone.value = page.page.list[i].telephone;
                            }
                            modify1(page.page.list[i].userId);
                        })
                    }
                    goback1.addEventListener("click", function () {
                        modify_user1.style.display = "none";
                    })
                }
            }
        })

    })
    fenYe(1, 12);
// 分页查询
    var pre = document.querySelectorAll(".pre");
    var next = document.querySelectorAll(".next");
    var mid = document.querySelectorAll(".pre-next-mid");
    var pageNow = document.querySelectorAll(".pageNow");
    var title = document.querySelectorAll(".paging-title-p");

    var pre1 = pre[0];
    var next1 = next[0];
    var mid1 = mid[0];
    var pageNow1 = pageNow[0];
    var title1 = title[0];
    next1.addEventListener("click", function () {
        var x = mid1.value;
        if (tb1.innerHTML == "") {
            x --;
        } else {
            x++;
        }
        fenYe(x, 12)
        mid1.value = x;
        pageNow1.value = x;
    })
    pre1.addEventListener("click", function () {
        var x = mid1.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe(x, 12);
        mid1.value = x;
        pageNow1.value = x;
    })
    // 分页查找
    var define = document.querySelectorAll(".define");
    var define1 = define[1];
    define1.addEventListener("click", function () {
        var x = pageNow1.value;
        fenYe(x, 12);
        mid1.value = x;
    })
    // 删除用户
    function deluser(de) {
        $.ajax({
            type: "post",
            url: "/admin/deleteUser",
            data: {
                userId: de
            },
            success: function (page) {
                fenYe(mid1.value, 12);
            }
        })
    }
// 修改用户
    function modify1(x) {
        var nickname1 = document.querySelector(".nickname");
        var rName1 = document.querySelector(".rName");
        var sex1 = document.querySelector(".sex");
        var telephone1 = document.querySelector(".telephone");
        var modify_user1=document.querySelectorAll(".modify-user")[0];
        $(".btn-modify").eq(0).off().on("click",function(){
            if(telephone1.value.length!==11){
                alert("手机格式出错")
            }else {
                $.ajax({
                    type: "post",
                    url: "/admin/updateUser",
                    data: {
                        nickname: nickname1.value,
                        rName: rName1.value,
                        sex: sex1.value,
                        telephone: telephone1.value,
                        userId: x
                    },
                    success: function (page) {
                        if (page.msg == "修改成功") {
                            alert("修改成功")
                            modify_user1.style.display = "none";
                            fenYe(mid1.value, 12)
                        } else {
                            alert(page.msg)
                        }

                    }
                })
            }
        })
    }

// 二、商品管理
    var tb2 = tb[1];
    function fenYe1(a, b) {
        tb2.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectGoodsByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    var x="";
                    var goodsName;
                    if(page.page.list[i].goodsName.length>10){
                        for (var j=0;j<=10;j++) {
                            x = x + page.page.list[i].goodsName[j];
                            goodsName=x+"...";
                        }
                    }else{
                        x=page.page.list[i].goodsName;
                        goodsName=x;
                    }
                    let list = `<tr>
                                    <td>${goodsName}</td>
                                    <td>${page.page.list[i].goodsPrice}</td>
                                    <td>${page.page.list[i].goodsSales}</td>
                                    <td>${page.page.list[i].goodsStock}</td>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].goodsType}</td>
                                    <td>${page.page.list[i].goodsBrand}</td>
                                    <td><button class='delete-2'>删除</button></td>
                               </tr>`;
                    tb2.insertAdjacentHTML("beforeend", list);
                }
                // 删除商品
                for (let i = 0; i < page.page.list.length; i++) {
                    var delete_2 = document.querySelectorAll(".delete-2")
                    delete_2[i].addEventListener("click", function () {
                        if (confirm("你确定删除?")) {
                            alert("删除成功");
                            delgoods(page.page.list[i].goodsId);
                        }else{
                            alert("删除失败");
                            fenYe1(mid2.value,10);
                        }

                    });
                }
            }
        });
    }

    fenYe1(1, 10);
    // 搜索
    var search_input2=document.querySelector(".search-input-2");
    var search_btn2=document.querySelector(".search-btn-2");
    search_btn2.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeGoodsByPage",
            data: {
                goodsName: search_input2.value,
                pageNow: 1,
                pageSize: 10
            },
            success: function (page) {
                if (search_input2.value == "") {
                    alert("输入的内容为空")
                    fenYe1(1, 10);
                    nodata[1].style.display = "none";
                } else {
                    tb2.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        var x="";
                        var goodsName;
                        if(page.page.list[i].goodsName.length>10){
                            for (var j=0;j<=10;j++) {
                                x = x + page.page.list[i].goodsName[j];
                                goodsName=x+"...";
                            }
                        }else{
                            x=page.page.list[i].goodsName;
                            goodsName=x;
                        }
                        let list = `<tr>
                                    <td>${goodsName}</td>
                                    <td>${page.page.list[i].goodsPrice}</td>
                                    <td>${page.page.list[i].goodsSales}</td>
                                    <td>${page.page.list[i].goodsStock}</td>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].goodsType}</td>
                                    <td>${page.page.list[i].goodsBrand}</td>
                                    <td><button class='delete-2'>删除</button></td>
                               </tr>`;
                        tb2.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb2.innerHTML==""){
                        alert("对不起,找不到搜索内容");
                        nodata[1].style.display="block";
                        paging[1].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[1].style.display = "none";
                        paging[1].style.display = "block";
                    }
                    // 删除商品
                    for (let i = 0; i < page.page.list.length; i++) {
                        var delete_2 = document.querySelectorAll(".delete-2")
                        delete_2[i].addEventListener("click", function () {
                            if (confirm("你确定删除?")) {
                                alert("删除成功");
                                delgoods(page.page.list[i].goodsId);
                            }else{
                                alert("删除失败");
                                fenYe1(mid2.value,10);
                            }

                        });
                    }
                }
            }
        })

    })
    // // 分页查询
    var pre2 = pre[1];
    var next2 = next[1];
    var mid2 = mid[1];
    var pageNow2 = pageNow[1];
    var title2 = title[1];
    next2.addEventListener("click", function () {
        var x = mid2.value;
        if (tb2.innerHTML == "") {
            x - 1;
        } else {
            x++;
        }
        fenYe1(x, 10)
        mid2.value = x;
        pageNow2.value = x;
    })
    pre2.addEventListener("click", function () {
        var x = mid2.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe1(x, 10);
        mid2.value = x;
        pageNow2.value = x;
    })
    // 分页查找
    var define2 = define[1];
    define2.addEventListener("click", function () {
        var x = pageNow2.value;
        fenYe1(x, 10);
        mid2.value = x;
    })
    // 删除商品
    function delgoods(de) {
        $.ajax({
            type: "post",
            url: "/admin/deleteGoods",
            data: {
                goodsId: de
            },
            success: function (page) {
                fenYe1(mid2.value, 10);
            }
        })
    }

    // 三、店铺管理
    var tb3 = tb[2];
    function fenYe2(a, b) {
        tb3.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectShopByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    let list = `<tr>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].nickName}</td>
                                    <td>${page.page.list[i].reputation}</td>
                                    <td><button class='delete-3'>删除</button></td>
                               </tr>`;
                    tb3.insertAdjacentHTML("beforeend", list);
                }
                var delete_3=document.querySelectorAll(".delete-3");
                for(let i=0;i<page.page.list.length;i++) {
                    delete_3[i].addEventListener("click", function () {
                        if (confirm("你确定删除?")) {
                            delshop(page.page.list[i].shopId);
                            alert("删除成功");
                        } else {
                            alert("删除失败");
                        }
                    })
                }
            }
        });
    }

    fenYe2(1, 10);
    // 搜索
    var search_input3=document.querySelector(".search-input-3");
    var search_btn3=document.querySelector(".search-btn-3");
    search_btn3.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeShopByPage",
            data: {
                shopName: search_input3.value,
                pageNow: 1,
                pageSize: 10
            },
            success: function (page) {
                if (search_input3.value == "") {
                    alert("输入的内容为空")
                    fenYe2(1, 10);
                    nodata[2].style.display = "none";
                } else {
                    tb3.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        let list = `<tr>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].nickName}</td>
                                    <td>${page.page.list[i].reputation}</td>
                                    <td><button class='delete-3'>删除</button></td>
                               </tr>`;
                        tb3.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb3.innerHTML==""){
                        alert("对不起,找不到你搜索的内容");
                        nodata[2].style.display="block";
                        paging[2].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[2].style.display = "none";
                        paging[2].style.display = "block";
                    }
                    var delete_3=document.querySelectorAll(".delete-3");
                    for(let i=0;i<page.page.list.length;i++) {
                        delete_3[i].addEventListener("click", function () {
                            if (confirm("你确定删除?")) {
                                delshop(page.page.list[i].shopId);
                                alert("删除成功");
                            } else {
                                alert("删除失败");
                            }
                        })
                    }
                }
            }
        })

    })
    // // 分页查询
    var pre3 = pre[2];
    var next3 = next[2];
    var mid3 = mid[2];
    var pageNow3 = pageNow[2];
    var title3 = title[2];
    next3.addEventListener("click", function () {
        var x = mid3.value;
        if (tb3.innerHTML == "") {
            x - 1;
        } else {
            x++;
        }
        fenYe2(x, 10)
        mid3.value = x;
        pageNow3.value = x;
    })
    pre3.addEventListener("click", function () {
        var x = mid3.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe2(x, 10);
        mid3.value = x;
        pageNow3.value = x;
    })
    // 分页查找
    var define3 = define[2];
    define3.addEventListener("click", function () {
        var x = pageNow3.value;
        fenYe2(x, 10);
        mid3.value = x;
    })
    // 删除店铺
    function delshop(de) {
        $.ajax({
            type: "post",
            url: "/admin/deleteShop",
            data: {
                shopId: de
            },
            success: function (page) {
                fenYe2(mid3.value, 10);
            }
        })
    }
    // 四、商家管理
    var tb4 = tb[3];

    function fenYe3(a, b) {
        tb4.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectShopperByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    var sex=page.page.list[i].sex||"无";
                    var telephone=page.page.list[i].telephone||"无";
                    var idCard=page.page.list[i].idCard||"无";
                    var rName=page.page.list[i].rName||"无";
                    let list = `<tr>
                                    
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='delete-1'>删除</button><button class='modify-1'>修改</button></td>
                               </tr>`;
                    tb4.insertAdjacentHTML("beforeend", list);
                }
                // 删除商家
                var delete_4=document.querySelectorAll(".delete-4");
                for(let i=0;i<page.page.list.length;i++) {
                    delete_4[i].addEventListener("click", function () {
                        if (confirm("你确定删除?")) {
                            delstore(page.page.list[i].userId);
                            alert("删除成功");
                        } else {
                            alert("删除失败");
                        }
                    })
                }
                // 修改中input中显示之前的值
                var age=document.querySelectorAll(".age")[3];
                var idCard=document.querySelectorAll(".idCard")[3];
                var nickname=document.querySelectorAll(".nickname")[3];
                var rName=document.querySelectorAll(".rName")[3];
                var sex=document.querySelectorAll(".sex")[3];
                var telephone=document.querySelectorAll(".telephone")[3];
                // 修改
                var modify_4=document.querySelectorAll(".modify-4");
                var modify_user4=document.querySelectorAll(".modify-user")[3];
                var goback4=document.querySelectorAll(".btn-goback")[3];
                for(let i=0;i<page.page.list.length;i++) {
                    modify_4[i].addEventListener("click", function () {
                        modify_user4.style.display = "block";
                        age.value=page.page.list[i].age;
                        idCard.value=page.page.list[i].idCard;
                        nickname.value=page.page.list[i].nickname;
                        rName.value=page.page.list[i].rName;
                        sex.value=page.page.list[i].sex;
                        telephone.value=page.page.list[i].telephone;
                        modify4(page.page.list[i].userId);
                    })
                }
                goback4.addEventListener("click", function () {
                    modify_user4.style.display = "none";
                })
            }
        });
    }

    fenYe3(1, 10);
    // 搜索
    var search_input4=document.querySelector(".search-input-4");
    var search_btn4=document.querySelector(".search-btn-4");
    search_btn4.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeShopperByPage",
            data: {
                nickName: search_input4.value,
                pageNow: 1,
                pageSize: 10
            },
            success: function (page) {
                if (search_input4.value == "") {
                    alert("输入的内容为空")
                    fenYe3(1, 10);
                    nodata[3].style.display = "none";
                } else {
                    tb4.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        var sex=page.page.list[i].sex||"无";
                        var telephone=page.page.list[i].telephone||"无";
                        var idCard=page.page.list[i].idCard||"无";
                        var rName=page.page.list[i].rName||"无";
                        let list = `<tr>
                                   
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='delete-1'>删除</button><button class='modify-1'>修改</button></td>
                               </tr>`;
                        tb4.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb4.innerHTML==""){
                        alert("对不起,找不到搜索内容");
                        nodata[3].style.display="block";
                        paging[3].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[3].style.display = "none";
                        paging[3].style.display = "block";
                    }
                    // 删除商家
                    var delete_4=document.querySelectorAll(".delete-4");
                    for(let i=0;i<page.page.list.length;i++) {
                        delete_4[i].addEventListener("click", function () {
                            if (confirm("你确定删除?")) {
                                delstore(page.page.list[i].userId);
                                alert("删除成功");
                            } else {
                                alert("删除失败");
                            }
                        })
                    }
                    // 修改中input中显示之前的值
                    var age=document.querySelectorAll(".age")[3];
                    var idCard=document.querySelectorAll(".idCard")[3];
                    var nickname=document.querySelectorAll(".nickname")[3];
                    var rName=document.querySelectorAll(".rName")[3];
                    var sex=document.querySelectorAll(".sex")[3];
                    var telephone=document.querySelectorAll(".telephone")[3];
                    // 修改
                    var modify_4=document.querySelectorAll(".modify-4");
                    var modify_user4=document.querySelectorAll(".modify-user")[3];
                    var goback4=document.querySelectorAll(".btn-goback")[3];
                    for(let i=0;i<page.page.list.length;i++) {
                        modify_4[i].addEventListener("click", function () {
                            modify_user4.style.display = "block";
                            age.value=page.page.list[i].age;
                            idCard.value=page.page.list[i].idCard;
                            nickname.value=page.page.list[i].nickname;
                            rName.value=page.page.list[i].rName;
                            sex.value=page.page.list[i].sex;
                            telephone.value=page.page.list[i].telephone;
                            modify4(page.page.list[i].userId);
                        })
                    }
                    goback4.addEventListener("click", function () {
                        modify_user4.style.display = "none";
                    })
                }
            }
        })

    })
    // // 分页查询
    var pre4 = pre[3];
    var next4 = next[3];
    var mid4 = mid[3];
    var pageNow4 = pageNow[3];
    var title4 = title[3];
    next4.addEventListener("click", function () {
        var x = mid4.value;
        if (tb4.innerHTML == "") {
            x - 1;
        } else {
            x++;
        }
        fenYe3(x, 10)
        mid4.value = x;
        pageNow4.value = x;
    })
    pre4.addEventListener("click", function () {
        var x = mid4.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe3(x, 10);
        mid4.value = x;
        pageNow4.value = x;
    })
    // 分页查找
    var define4 = define[3];
    define4.addEventListener("click", function () {
        var x = pageNow4.value;
        fenYe3(x, 10);
        mid4.value = x;
    })
    // 删除商家
    function delstore(de) {
        $.ajax({
            type: "post",
            url: "/admin/deleteShopper",
            data: {
                userId: de
            },
            success: function (page) {
                fenYe3(mid4.value, 10);
            }
        })
    }
    // 修改商家
    function modify4(x) {

        var age2 = document.querySelector(".age");
        var idCard2 = document.querySelector(".idCard");
        var nickname2 = document.querySelector(".nickname");
        var rName2 = document.querySelector(".rName");
        var sex2 = document.querySelector(".sex");
        var telephone2 = document.querySelector(".telephone");
        $(".btn-modify").eq(3).off().on("click",function(){
            $.ajax({
                type: "post",
                url: "/admin/updateShopper",
                data: {
                    age: age2.value,
                    idCard: idCard2.value,
                    nickname: nickname2.value,
                    rName: rName2.value,
                    sex: sex2.value,
                    telephone: telephone2.value,
                    userId: x
                },
                success: function (page) {
                    alert("修改成功")
                    fenYe3(mid4.value,10);
                }
            })
        })
    }
    // 五、申请商品上架
    var tb5 = tb[4];
    function fenYe4(a, b) {
        tb5.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectGoodsToBePutOnSaleByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    var x="";
                    var goodsName;
                    if(page.page.list[i].goodsName.length>10){
                        for (var j=0;j<=10;j++) {
                            x = x + page.page.list[i].goodsName[j];
                            goodsName=x+"...";
                        }
                    }else{
                        x=page.page.list[i].goodsName;
                        goodsName=x;
                    }
                    let list = `<tr>
                                    <td>${goodsName}</td>
                                    <td>${page.page.list[i].goodsPrice}</td>
                                    <td>${page.page.list[i].goodsSales}</td>
                                    <td>${page.page.list[i].goodsStock}</td>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].goodsType}</td>
                                    <td>${page.page.list[i].goodsBrand}</td>
                                    <td><button class='agree-1'>同意</button><button class='disagree-1'>不同意</button></td>
                               </tr>`;
                    tb5.insertAdjacentHTML("beforeend", list);
                    // var tr = document.createElement("tr");
                    // var td2 = document.createElement("td");
                    // var td3 = document.createElement("td");
                    // var td4 = document.createElement("td");
                    // var td5 = document.createElement("td");
                    // var td6 = document.createElement("td");
                    // var td8 = document.createElement("td");
                    // var td9 = document.createElement("td");
                    // var td10 = document.createElement("td");
                    // // tr.appendChild("td1").innerHtml="<input type=checkbox />";
                    // // tr.appendChild(td2).innerHTML = page.page.list[i].goodsName;
                    // var x="";
                    // if(page.page.list[i].goodsName.length>10){
                    //     for (var j=0;j<=10;j++) {
                    //         x =x+page.page.list[i].goodsName[j];
                    //         // tr.appendChild(td2).innerHTML=x;
                    //     }
                    //     tr.appendChild(td2).innerHTML=x+"...";
                    // }else{
                    //     tr.appendChild(td2).innerHTML=page.page.list[i].goodsName;
                    // }
                    // tr.appendChild(td3).innerHTML = page.page.list[i].goodsPrice;
                    // tr.appendChild(td4).innerHTML = page.page.list[i].goodsSales;
                    // tr.appendChild(td5).innerHTML = page.page.list[i].goodsStock;
                    // tr.appendChild(td6).innerHTML = page.page.list[i].shopName;
                    // tr.appendChild(td8).innerHTML = page.page.list[i].goodsType;
                    // tr.appendChild(td9).innerHTML = page.page.list[i].goodsBrand;
                    // tr.appendChild(td10).innerHTML = "<button class='agree-1'>同意</button><button class='disagree-1'>不同意</button>";
                    // tb5.appendChild(tr);
                }
                var agree_1=document.querySelectorAll(".agree-1");
                var disagree_1=document.querySelectorAll(".disagree-1");
                for(let i=0;i<page.page.list.length;i++){
                    agree_1[i].addEventListener("click",function () {
                        if(confirm("同意申请成为商家?")){
                            agree1(page.page.list[i].userId);
                            alert("成为商家");
                        }
                    })
                    disagree_1[i].addEventListener("click",function () {
                        if(confirm("不同意申请成为商家?")){
                            disagree1(page.page.list[i].userId);
                            alert("不能成为商家");
                        }
                    })
                }
            }
        });
    }

    fenYe4(1, 10);
    // 搜索
    var search_input5=document.querySelector(".search-input-5");
    var search_btn5=document.querySelector(".search-btn-5");
    search_btn5.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeGoodsToBePutOnSaleByPage",
            data: {
                goodsName: search_input5.value,
                pageNow: 1,
                pageSize: 10
            },
            success: function (page) {
                if (search_input5.value == "") {
                    alert("输入的内容为空")
                    fenYe4(1, 10);
                    nodata[4].style.display = "none";
                } else {
                    tb5.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        var x="";
                        var goodsName;
                        if(page.page.list[i].goodsName.length>10){
                            for (var j=0;j<=10;j++) {
                                x = x + page.page.list[i].goodsName[j];
                                goodsName=x+"...";
                            }
                        }else{
                            x=page.page.list[i].goodsName;
                            goodsName=x;
                        }
                        let list = `<tr>
                                    <td>${goodsName}</td>
                                    <td>${page.page.list[i].goodsPrice}</td>
                                    <td>${page.page.list[i].goodsSales}</td>
                                    <td>${page.page.list[i].goodsStock}</td>
                                    <td>${page.page.list[i].shopName}</td>
                                    <td>${page.page.list[i].goodsType}</td>
                                    <td>${page.page.list[i].goodsBrand}</td>
                                    <td><button class='agree-1'>同意</button><button class='disagree-1'>不同意</button></td>
                               </tr>`;
                        tb5.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb5.innerHTML==""){
                        alert("对不起,找不到搜索内容");
                        nodata[4].style.display="block";
                        paging[4].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[4].style.display = "none";
                        paging[4].style.display = "block";
                    }
                    var agree_1=document.querySelectorAll(".agree-1");
                    var disagree_1=document.querySelectorAll(".disagree-1");
                    for(let i=0;i<page.page.list.length;i++){
                        agree_1[i].addEventListener("click",function () {
                            if(confirm("同意商品上架?")){
                                agree1(page.page.list[i].userId);
                                alert("同意");
                            }
                        })
                        disagree_1[i].addEventListener("click",function () {
                            if(confirm("不同意商品上架?")){
                                disagree1(page.page.list[i].userId);
                                alert("不能上架");
                            }
                        })
                    }
                }
            }
        })

    })
    // // 分页查询
    var pre5 = pre[4];
    var next5 = next[4];
    var mid5 = mid[4];
    var pageNow5 = pageNow[4];
    var title5 = title[4];
    next5.addEventListener("click", function () {
        var x = mid5.value;
        if (tb5.innerHTML == "") {
            x - 1;
        } else {
            x++;
        }
        fenYe4(x, 10)
        mid5.value = x;
        pageNow5.value = x;
    })
    pre5.addEventListener("click", function () {
        var x = mid5.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe4(x, 10);
        mid5.value = x;
        pageNow5.value = x;
    })
    // 分页查找
    var define5 = define[4];
    define5.addEventListener("click", function () {
        var x = pageNow5.value;
        fenYe4(x, 10);
        mid5.value = x;
    })
    // 申请商品上架

    // 同意
    function agree1(ag) {
        $.ajax({
            type: "post",
            url: "/admin/agreeGoodsToBePutOnSale",
            data: {
                goodsId: ag
            },
            success: function (page) {
                fenYe4(mid5.value, 12);
            }
        })
    }
    // 不同意
    function disagree1(ag) {
        $.ajax({
            type: "post",
            url: "/admin/disagreeGoodsToBePutOnSale",
            data: {
                goodsId: ag
            },
            success: function (page) {
                fenYe4(mid5.value, 12);
            }
        })
    }
    // 六、申请成为用户
    var tb6 = tb[5];
    function fenYe5(a, b) {
        tb6.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/admin/selectUserToBeShopperByPage",
            data: {
                pageNow: a,
                pageSize: b
            },
            success: function (page) {
                for (let i = 0; i < page.page.list.length; i++) {
                    var sex=page.page.list[i].sex||"无";
                    var telephone=page.page.list[i].telephone||"无";
                    var idCard=page.page.list[i].idCard||"无";
                    var rName=page.page.list[i].rName||"无";
                    let list = `<tr>
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='agree-2'>同意</button><button class='disagree-2'>不同意</button></td>
                               </tr>`;
                    tb6.insertAdjacentHTML("beforeend", list);
                }
                var agree_2=document.querySelectorAll(".agree-2");
                var disagree_2=document.querySelectorAll(".disagree-2");
                for(let i=0;i<page.page.list.length;i++){
                    agree_2[i].addEventListener("click",function () {
                        if(confirm("同意申请成为商家?")){
                            agree1(page.page.list[i].userId);
                            alert("成为商家");
                        }
                    })
                    disagree_2[i].addEventListener("click",function () {
                        if(confirm("不同意申请成为商家?")){
                            disagree1(page.page.list[i].userId);
                            alert("不能成为商家");
                        }
                    })
                }
            }
        });

    }

    fenYe5(1, 10);
    // 搜索
    var search_input6=document.querySelector(".search-input-6");
    var search_btn6=document.querySelector(".search-btn-6");
    search_btn6.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/admin/likeUserToBeShopperByPage",
            data: {
                nickName: search_input6.value,
                pageNow: 1,
                pageSize: 10
            },
            success: function (page) {
                if (search_input6.value == "") {
                    alert("输入的内容为空")
                    fenYe5(1, 10);
                    nodata[5].style.display = "none";
                } else {
                    tb6.innerHTML = "";
                    for (let i = 0; i < page.page.list.length; i++) {
                        var sex=page.page.list[i].sex||"无";
                        var telephone=page.page.list[i].telephone||"无";
                        var idCard=page.page.list[i].idCard||"无";
                        var rName=page.page.list[i].rName||"无";
                        let list = `<tr> 
                                    <td>${page.page.list[i].nickname}</td>
                                    <td>${sex}</td>
                                    <td>${page.page.list[i].age}</td>
                                    <td>${telephone}</td>
                                    <td>${page.page.list[i].email}</td>
                                    <td>${idCard}</td>
                                    <td>${rName}</td>
                                    <td><button class='agree-2'>同意</button><button class='disagree-2'>不同意</button></td>
                               </tr>`;
                        tb6.insertAdjacentHTML("beforeend", list);
                    }
                    if(tb6.innerHTML==""){
                        alert("对不起,找不到搜索内容");
                        nodata[5].style.display="block";
                        paging[5].style.display="none";
                    }else {
                        alert("搜索成功")
                        nodata[5].style.display = "none";
                        paging[5].style.display = "block";
                    }
                    var agree_2=document.querySelectorAll(".agree-2");
                    var disagree_2=document.querySelectorAll(".disagree-2");
                    for(let i=0;i<page.page.list.length;i++){
                        agree_2[i].addEventListener("click",function () {
                            if(confirm("同意申请成为商家?")){
                                agree2(page.page.list[i].userId);
                                alert("成为商家");
                            }
                        })
                        disagree_2[i].addEventListener("click",function () {
                            if(confirm("不同意申请成为商家?")){
                                disagree2(page.page.list[i].userId);
                                alert("不能成为商家");
                            }
                        })
                    }
                }
            }
        })

    })
    // // 分页查询
    var pre6 = pre[5];
    var next6 = next[5];
    var mid6 = mid[5];
    var pageNow6 = pageNow[5];
    var title6 = title[5];
    next6.addEventListener("click", function () {
        var x = mid6.value;
        if (tb6.innerHTML == "") {
            x - 1;
        } else {
            x++;
        }
        fenYe5(x, 10)
        mid6.value = x;
        pageNow6.value = x;
    })
    pre6.addEventListener("click", function () {
        var x = mid6.value;
        x--;
        if (x == 0) {
            x = 1;
        } else if (x <= 0) {

        }
        fenYe5(x, 10);
        mid6.value = x;
        pageNow6.value = x;
    })
    // 分页查找
    var define6 = define[5];
    define6.addEventListener("click", function () {
        var x = pageNow6.value;
        fenYe5(x, 10);
        mid6.value = x;
    })
    // 申请成为商家

    // 同意
    function agree2(ag) {
        $.ajax({
            type: "post",
            url: "/admin/agreeUserToBeShopper",
            data: {
                userId: ag
            },
            success: function (page) {
                fenYe5(mid6.value, 10);
            }
        })
    }
    // 不同意
    function disagree2(ag) {
        $.ajax({
            type: "post",
            url: "/admin/disagreeUserToBeShopper",
            data: {
                userId: ag
            },
            success: function (page) {
                fenYe5(mid6.value, 10);
            }
        })
    }
}


